/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/03
*/
#include "LuaProgress.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (Progress::ToProgress(m_cobj))

void* LuaProgress::GetInterface(void* data)
{
    if (!data) return 0;
    LuaProgress* progress = new LuaProgress((Progress*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaProgress] new LuaProgress : %d, %d", progress, data);
#endif
    return progress;
}

void LuaProgress::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaProgress] delete LuaProgress : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaProgress::LuaProgress(Progress* progress) : LuaControl(progress)
{}

LuaProgress::~LuaProgress()
{}

//----------------------------------------//

int LuaProgress::GetValue()
{
    return CObjPtr->GetValue();
}

bool LuaProgress::SetValue(int val)
{
    return CObjPtr->SetValue(val);
}

void LuaProgress::SetMaxValue(int val)
{
    CObjPtr->SetMaxValue(val);
}

int LuaProgress::GetMaxValue()
{
    return CObjPtr->GetMaxValue();
}

void LuaProgress::SetMinValue(int val)
{
    CObjPtr->SetMinValue(val);
}

int LuaProgress::GetMinValue()
{
    return CObjPtr->GetMinValue();
}

void LuaProgress::SetType(const char* type)
{
    CObjPtr->SetType(type);
}

const char* LuaProgress::GetType()
{
    return CObjPtr->GetType();
}

bool LuaProgress::SetBarInset(int l, int t, int r, int b)
{
    Rect1 data(l, t, r, b);
    return CObjPtr->SetBarInset(&data);
}

int LuaProgress::GetBarInset(LuaState *L)
{
    Rect1 rc1 = CObjPtr->GetBarInset();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc1);
    obj.Push(L);
    return 1;
}

int LuaProgress::GetBarRect(LuaState *L)
{
    Rect rc = CObjPtr->GetBarRect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

int LuaProgress::GetBarBkRect(LuaState *L)
{
    Rect rc = CObjPtr->GetBarBkRect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

//----------------------------------------//

void LuaProgress::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "Progress", "Control");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaProgress::GetInterface);

    obj.RegisterObjectDirect("SetValue", (LuaProgress*)0, &LuaProgress::SetValue);
    obj.RegisterObjectDirect("GetValue", (LuaProgress*)0, &LuaProgress::GetValue);
    obj.RegisterObjectDirect("SetMaxValue", (LuaProgress*)0, &LuaProgress::SetMaxValue);
    obj.RegisterObjectDirect("GetMaxValue", (LuaProgress*)0, &LuaProgress::GetMaxValue);
    obj.RegisterObjectDirect("SetMinValue", (LuaProgress*)0, &LuaProgress::SetMinValue);
    obj.RegisterObjectDirect("GetMinValue", (LuaProgress*)0, &LuaProgress::GetMinValue);
    obj.RegisterObjectDirect("SetType", (LuaProgress*)0, &LuaProgress::SetType);
    obj.RegisterObjectDirect("GetType", (LuaProgress*)0, &LuaProgress::GetType);
    obj.RegisterObjectDirect("SetBarInset", (LuaProgress*)0, &LuaProgress::SetBarInset);
    obj.RegisterObjectFunctor("GetBarInset", &LuaProgress::GetBarInset);
    obj.RegisterObjectFunctor("GetBarRect", &LuaProgress::GetBarRect);
    obj.RegisterObjectFunctor("GetBarBkRect", &LuaProgress::GetBarBkRect);

}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif